#include <stdio.h>
#include "drm_drv/drm_plane_drv.h"
#include "display_mode.h"

//screen_no,
//screen123456,
//screen14x25x36,
//screen1x25x3x4x6,
//screen123x4x5x6,
//screen1x2x3x456,
//gwj:verimpotant
//unsigned int pipe_mode_count[10]={0,1,3,5,4,4,6,2,6,6};

void screen_mode(struct plane_arg *plane,int plane_cnt,display_mode mode,int alpha){

   static display_mode last_mode;
    unsigned int fourcc=DRM_FORMAT_RGB888;

    if(last_mode==mode){
        printf("mode same,no init\r\n");
        return;
    }
    if(last_mode!=screen_no){
//        for(int i=0;i<pipe_mode_count[last_mode];i++){
//            plane_destroy(&plane[i]);
//        }
        plane_destroy_all(plane,plane_cnt);
    }
    switch (mode) {
    case screen_no:
        break;
    case screen123456:
        init_plane(&plane[0],33,1920,720,0,0,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        break;
    case screen14x25x36:
        init_plane(&plane[0],33,640,720,0,0,fourcc);
        init_plane(&plane[1],34,640,720,640,0,fourcc);
        init_plane(&plane[2],35,640,720,1280,0,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        drm_set_plane_prop( 34, "alpha", alpha);
        drm_set_plane_prop( 35, "alpha", alpha);
        break;
    case screen1x25x3x4x6:
        init_plane(&plane[0],33,640,360,0,0,fourcc);
        init_plane(&plane[1],34,640,720,640,0,fourcc);
        init_plane(&plane[2],35,640,360,1280,0,fourcc);
        init_plane(&plane[3],36,640,360,0,360,fourcc);
        init_plane(&plane[4],37,640,360,1280,360,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        drm_set_plane_prop( 34, "alpha", alpha);
        drm_set_plane_prop( 35, "alpha", alpha);
        drm_set_plane_prop( 36, "alpha", alpha);
        drm_set_plane_prop( 37, "alpha", alpha);
        break;
    case screen123x4x5x6:
        init_plane(&plane[0],33,1920,360,0,0,fourcc);
        init_plane(&plane[1],34,640,360,0,360,fourcc);
        init_plane(&plane[2],35,640,360,640,360,fourcc);
        init_plane(&plane[3],36,640,360,1280,360,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        drm_set_plane_prop( 34, "alpha", alpha);
        drm_set_plane_prop( 35, "alpha", alpha);
        drm_set_plane_prop( 36, "alpha", alpha);
        break;
    case screen1x2x3x456:
        init_plane(&plane[0],33,640,360,0,0,fourcc);
        init_plane(&plane[1],34,640,360,640,0,fourcc);
        init_plane(&plane[2],35,640,360,1280,0,fourcc);
        init_plane(&plane[3],36,1920,360,0,360,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        drm_set_plane_prop( 34, "alpha", alpha);
        drm_set_plane_prop( 35, "alpha", alpha);
        drm_set_plane_prop( 36, "alpha", alpha);
        break;
    case screen1x2x3x4x5x6:
        init_plane(&plane[0],33,640,360,0,0,fourcc);
        init_plane(&plane[1],34,640,360,640,0,fourcc);
        init_plane(&plane[2],35,640,360,1280,0,fourcc);
        init_plane(&plane[3],36,640,360,0,360,fourcc);
        init_plane(&plane[4],37,640,360,640,360,fourcc);
        init_plane(&plane[5],38,640,360,1280,360,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        drm_set_plane_prop( 34, "alpha", alpha);
        drm_set_plane_prop( 35, "alpha", alpha);
        drm_set_plane_prop( 36, "alpha", alpha);
        drm_set_plane_prop( 37, "alpha", alpha);
        drm_set_plane_prop( 38, "alpha", alpha);
        break;
    case screen1425x2536 :
        init_plane(&plane[0],33,960,720,0,0,fourcc);
        init_plane(&plane[1],34,960,720,960,0,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        drm_set_plane_prop( 34, "alpha", alpha);
        break;
    case screen14x25x36_fzjs:
        init_plane(&plane[0],33,480,720,0,0,fourcc);
        init_plane(&plane[1],34,960,720,480,0,fourcc);
        init_plane(&plane[2],35,480,720,1440,0,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        drm_set_plane_prop( 34, "alpha", alpha);
        drm_set_plane_prop( 35, "alpha", alpha);
        break;
    case screen1x25x3x4x6_fzjs:
        init_plane(&plane[0],33,480,360,0,0,fourcc);
        init_plane(&plane[1],34,960,720,480,0,fourcc);
        init_plane(&plane[2],35,480,360,1440,0,fourcc);
        init_plane(&plane[3],36,480,360,0,360,fourcc);
        init_plane(&plane[4],37,480,360,1440,360,fourcc);
        drm_set_plane_prop( 33, "alpha", alpha);
        drm_set_plane_prop( 34, "alpha", alpha);
        drm_set_plane_prop( 35, "alpha", alpha);
        drm_set_plane_prop( 36, "alpha", alpha);
        drm_set_plane_prop( 37, "alpha", alpha);
        break;
    }
    last_mode=mode;
};
